package com.ruoyi.business.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.domain.TEducationInfo;
import com.ruoyi.business.mapper.TEducationInfoMapper;
import com.ruoyi.business.service.ITEducationInfoService;
import com.ruoyi.business.vo.TEducationInfoVo;
import com.ruoyi.common.constant.RoleConstants;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 教育风采Service业务层处理
 *
 * @author Tellsea
 * @date 2024-01-17
 */
@Service
public class TEducationInfoServiceImpl extends ServiceImpl<TEducationInfoMapper, TEducationInfo> implements ITEducationInfoService {

    @Override
    public TableDataInfo<TEducationInfoVo> queryList(TEducationInfoVo entity) {
        if (!SecurityUtils.hasRole(RoleConstants.ADMIN.getRoleKey())
                && !SecurityUtils.hasRole(RoleConstants.SYSTEM.getRoleKey())
                && !SecurityUtils.hasRole(RoleConstants.STUDENT.getRoleKey())) {
            Long registerDeptId = SecurityUtils.getLoginUser().getRegisterDeptId();
            if (ObjectUtil.isEmpty(registerDeptId)) {
                return null;
            }
            entity.setRegisterDeptId(registerDeptId);
        }
        return PageUtils.buildDataInfo(this.baseMapper.queryList(PageUtils.buildPage(), entity));
    }

    @Override
    public List<TEducationInfoVo> queryAll(TEducationInfoVo entity) {
        if (!SecurityUtils.hasRole(RoleConstants.ADMIN.getRoleKey())
                && !SecurityUtils.hasRole(RoleConstants.SYSTEM.getRoleKey())
                && !SecurityUtils.hasRole(RoleConstants.STUDENT.getRoleKey())) {
            Long registerDeptId = SecurityUtils.getLoginUser().getRegisterDeptId();
            if (ObjectUtil.isEmpty(registerDeptId)) {
                return null;
            }
            entity.setRegisterDeptId(registerDeptId);
        }
        return this.baseMapper.queryList(entity);
    }

    @Override
    public TEducationInfoVo queryById(Long id) {
        return this.baseMapper.queryById(id);
    }
}
